<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>createRef</title>
</head>
<body>
    <script src="../React-js/react.development.js" type="text/javascript"></script>
    <script src="../React-js/react-dom.development.js" type="text/javascript"></script>
    <script src="../React-js/babel.min.js" type="text/javascript"></script>
    <div id="test"></div>
    <script type="text/babel">
        //受控和非受控组件区别
        //受控组件：value值由state控制
        //非受控组件：value值不由state控制
       class Login extends React.Component{
        myRef = React.createRef()
        handleSubmit = (event)=>{
            event.preventDefault()
            console.log(this.myRef.current.value);
            console.log(this.myRef1.current.value);
        }
        render(){
            return (
                <form action="http://www.baidu.com" onSubmit={this.handleSubmit}>
                    用户名：<input type="text" ref={this.myRef} name="username"/>
                    密码：<input type="password" ref={c=>this.myRef1=c} name="password"/>
                    <button>登录</button>
                </form>
            )
        }
       }
       ReactDOM.render(<Login/>,document.querySelector('#test'))
    </script>
</body>
</html>